package com.qbw.core.holder;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.qbw.app.R;
import com.qbw.app.databinding.HolderLoadBinding;
import com.qbw.core.base.BaseHolder;
import com.qbw.core.view.RefreshLoadLayout;


/**
 * @author qinbaowei
 * @createtime 2017/04/17 15:23
 * @email qbaowei@qq.com
 * @description 加载更多
 */


public class LoadHolder extends BaseHolder<RefreshLoadLayout.Load, HolderLoadBinding> {

    private RefreshLoadLayout.OnLoadFailedListener mOnLoadFailedListener;

    public LoadHolder(Context context,
                      ViewGroup viewParent,
                      RefreshLoadLayout.OnLoadFailedListener onLoadFailedListener) {
        super(context, R.layout.holder_load, viewParent);
        mOnLoadFailedListener = onLoadFailedListener;
    }

    @Override
    public void bindData(int position, final RefreshLoadLayout.Load data) {
        mBinding.setLoad(data);
        mBinding.executePendingBindings();
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (RefreshLoadLayout.Load.isLoadFailed(data.getStatus())) {
                    if (mOnLoadFailedListener != null) {
                        RefreshLoadLayout.Load.setLoadLoading(data);
                        mOnLoadFailedListener.onRetryLoad();
                    }
                }
            }
        });
    }
}
